//
//  PayFoodMaterialViewController.m
//  Menu
//
//  Created by dllo on 15/7/7.
//  Copyright (c) 2015年 lijiangang. All rights reserved.
//

#import "PayFoodMaterialViewController.h"

@interface PayFoodMaterialViewController ()

@end

@implementation PayFoodMaterialViewController

- (void)dealloc
{
    [_materialTableView release];
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.view.frame = CGRectMake(0, (260+40)*HEIGHT+64, MyWidth, MyHeight-260*HEIGHT-40*HEIGHT-64-49);
    self.materialTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, MyWidth, MyHeight-260*HEIGHT-40*HEIGHT-64-49) style:UITableViewStylePlain];
    self.materialTableView.backgroundColor = [UIColor whiteColor];
    self.materialTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.materialTableView.bounces = YES;
    [self.view addSubview:self.materialTableView];
    
    self.materialTableView.delegate = self;
    self.materialTableView.dataSource = self;
    [_materialTableView release];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *str = [NSString stringWithFormat:@"原料 : %@",self.payFood.materialPrepare];
    CGFloat height = [[self class] heightForcell:str];
    return height + 200*HEIGHT + 30*HEIGHT;
}

+(CGFloat)heightForcell:(NSString *)content
{
    //参数1.设置计算内容的宽和高
    //参数2.设置计算高度模式
    //参数3.设置计算字体大小属性
    //参数4.系统备用参数,设置为nil
    //其中宽度一定与显示内容的label宽度一致否则计算不准确  高度尽量大一些
    CGSize size=CGSizeMake(325*WIDTH, 10000);
    //字体大小一定与显示内容的label字体大小一致  默认是17.0
    NSDictionary *dic =[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17] forKey:NSFontAttributeName];
    CGRect frame=  [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *material = @"materialCell";
    PayFoodMaterialTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:material];
    if (cell == nil)
    {
        cell = [[PayFoodMaterialTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:material];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.payFoodModel = self.payFood;
    [cell.contentView sizeToFit];
    return cell;
}



























- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
